package com.linzm.structuraltype.adapter01.mediaplayer;

import com.linzm.structuraltype.adapter01.factory.MediaPlayerFactory;
import com.linzm.structuraltype.adapter01.enums.MediaTypeEnum;

/**
 * @Author zimingl
 * @Date 2023/4/15 21:56
 * @Description: MediaAdapter
 */
public class MediaAdapter implements MediaPlayer {
    AdvancedMediaPlayer advancedMusicPlayer;

    public MediaAdapter(String audioType) throws Exception {
        MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();
        advancedMusicPlayer = mediaPlayerFactory.getAdvancedMediaPlayer(audioType);
    }

    @Override
    public void play(String audioType, String fileName) {
        if (MediaTypeEnum.VLC.name().equalsIgnoreCase(audioType)) {
            advancedMusicPlayer.playVlc(fileName);
        }
        if (MediaTypeEnum.MP4.name().equalsIgnoreCase(audioType)) {
            advancedMusicPlayer.playMp4(fileName);
        }
    }
}
